﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.装饰者模式
{
    /// <summary>
    /// 装饰者模式 - Decorator Pattern
    /// 应用场景：
    /// 01.产品推荐组合，购买组合内产品会有优惠策略
    /// 02.主产品加配料计算总额，比如咖啡加糖与牛奶
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            DbSession dbSession = new DbSession();
            //Product coffee = new Product("coffee", 20);

            //Product sugar = new Product("sugar", 2);
            //Product milk = new Product("milk", 3);


            //Console.WriteLine(coffee.Price);
            //Product mixProduct = new ProductDecorator(coffee, sugar, milk);

            //Console.WriteLine(mixProduct.Price);

            //dbSession.Products.Add(mixProduct);
            //dbSession.SaveChanges();

            ProductDecorator decorator = dbSession.Products.OfType<ProductDecorator>().FirstOrDefault();

            Console.WriteLine(decorator.MainProduct.ProductName);
            foreach (var product in decorator.DecorativeProducts)
            {
                Console.WriteLine(product.ProductName);
            }

            Console.WriteLine(decorator.Price);


            Console.WriteLine("OK");
            Console.ReadKey();
        }
    }
}
